package com.yc.litemonitoringserver.server;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;


public class  LiteMonitoringServerInitializer extends ChannelInitializer<Channel> {

    private final static int MAX_OBJECT_SIZE = 1024 * 1024;
    private  EventLoopGroup businessGroup;

    public LiteMonitoringServerInitializer(EventLoopGroup businessGroup) {
        this.businessGroup = businessGroup;
    }






    @Override
    protected void initChannel(Channel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //设定编解码器
        pipeline.addLast(new ObjectDecoder(MAX_OBJECT_SIZE,
                ClassResolvers.weakCachingConcurrentResolver(this.getClass()
                        .getClassLoader())));
        pipeline.addLast(new ObjectEncoder());
        pipeline.addLast( businessGroup,  new LiteMonitoringServerHandler());
    }
}
